import { defineStore } from 'pinia';

export const useHistoryStore = defineStore('history', {
  state: () => {
    return {
      currentCity: uni.getStorageSync('city') || '',
      addCityArr: uni.getStorageSync('cityArr') || []
    };
  },
  actions: {
    // 设置当前所在城市
    setCurrentCity(city: string) {
      uni.setStorageSync('city', city);
      this.currentCity = city;
    },
    // 添加历史城市
    setHistoryCity(city: string) {
      this.addCityArr.push(city);
      uni.setStorageSync('cityArr', this.addCityArr);
    }
  }
});
